<template>
	<view class="wrap">
		<!-- <swiper class="swiper" :indicator-dots="false" circular interval=2000>
			<swiper-item class="swiper-box" v-for="(item, index) in info" :key="index">
				
			</swiper-item>
		</swiper> -->
		<js-error mode="bottom" ref="jsError"></js-error>
		<view style="padding: 10px;background-color: blue;color: #fff; font-size: 22px;">{{carea}} | {{cposcode==''?'':'【' + cposcode +'-'+ cposname +'】'}}</view>
		
		<scroll-view class="scroll-list bg-white" scroll-y="true" :style="[{height:stockListHeight + 'px'}]">
			<uni-table border emptyText="暂无更多数据">
			  <uni-tr v-for="(res, i) in blist" :key="i">
			    <uni-td align="center" style="background-color: blue;color:#fff">{{res.parent.cposname}}</uni-td>
				<uni-td align="center"  v-for="(item, index) in res.list" :key="index" 
				:class="item.binv=='1'?'have':(item.isRoot?'haveXz':'')">
					<view  @click="select(item)">
						<view >{{item.cposname}}</view>
					</view>
				</uni-td>
			  </uni-tr>
			</uni-table>
		</scroll-view>

		<view class="footer">
			<view class="confrim-btn padding padding-bottom-sm flex bg-white">
				<u-button type="primary" class="btn" style="width: 100%;" @click="cancel">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				stockListHeight: 0,
				list: [],
				blist:[],
				cposcode :'',
				cposname:'',
				carea:'',
				parentCode:'',
			}
		},
		onLoad(params) {
			this.parentCode = params.cposcode;
			this.carea = params.cposname;
			var _self = this;
			uni.getSystemInfo({
				success: (e) => { // resu 可以获取当前屏幕的高度
					_self.stockListHeight = e.windowHeight - uni.upx2px(255);
				},
				fail: (res) => {}
			});
			this.loadList();
		},
		watch: {

		},
		onShow() {},
		onReady() {},
		methods: {
			select(requet) {
				let arr = this.blist.map((res) =>{
					res = res.list.map((item) => {
						if (requet.cposcode == item.cposcode) {
							item.isRoot = true;
							this.cposcode = requet.cposcode;
							this.cposname = requet.cposname;
						}else{
							item.isRoot = false;
						}
						return item;
					})
					return res;
				});
				this.list = arr;
			},

			cancel() {
				uni.$emit('consult',{cposcode:this.cposcode,cposname:this.cposname});
				uni.navigateBack({
					delta: 2,
				})
			},

			loadList() {
				this.$u.api.basApi.findPosRowByOne({"parent.cposcode":this.parentCode}).then(res => {
					this.blist = res.data;
				})
			},
		}
	}
</script>
<style>
	@import '../asd.css';
	.have{
		background-color:red;
		color: #FFF;
	}
	
	.haveXz{
		background-color:green;
		color: #FFF;
	}
</style>